package com.rpframework.website.device.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.rpframework.core.BaseService;
import com.rpframework.utils.DateUtils;
import com.rpframework.utils.NumberUtils;
import com.rpframework.utils.Pager;
import com.rpframework.website.device.dao.IBalanceDao;
import com.rpframework.website.device.domain.Balance;

@Service
public class BalanceService extends BaseService{
public @Resource IBalanceDao iDao;

	
	public Pager<Balance> getPager(Pager<Balance> pager) {
		long startTime = System.currentTimeMillis();
		List<Balance> itemList = iDao.doPager(this.packageMyBatisParam(pager));
		pager.setItemList(itemList);
		pager.setCostTime(System.currentTimeMillis()-startTime);
		return pager;
	}

	/**
	 * 添加明细记录
	 * @param money 金额
	 * @param name 记录名称 
	 * @param type 1余额明细  2积分明细 
	 * @param userId 用户id
	 */
	public boolean addRecord(Double money, String name, int type, Integer userId) {
		Balance t = new Balance();
		t.setId(DateUtils.nowDate(DateUtils.YYYYMMDDHHMMSS)+ NumberUtils.random(5));
		t.setCreateTime(System.currentTimeMillis()/1000);
		t.setMoney(money);
		t.setName(name);
		t.setType(type);
		t.setState(1);
		t.setUserId(userId);
		return iDao.insert(t);
	}

}
